﻿@model TSites.Administrator.Models.PagingInfo
<div id="divPaging">
	Page @Model.PageIndex of @Model.TotalPages
	&nbsp;&nbsp;&nbsp;
	@{
		int currentPage = Model.PageIndex, totalPage = Model.TotalPages;
		int rightShow = 5, leftShow = 3;
		string paging = string.Empty;

		if (totalPage <= rightShow + leftShow)
		{
			@:<label class="pagingNumber"><<</label>
			@:<label class="pagingNumber"><</label>
			for (int i = 1; i <= totalPage; i++)
			{
				@:<label class="pagingNumber">@i</label>
			}
			@:<label class="pagingNumber">></label>
			@:<label class="pagingNumber">>></label>
		}
		else
		{
			if (currentPage <= leftShow)
			{
				@:<label class="pagingNumber"><<</label>
				@:<label class="pagingNumber"><</label>
				for (int i = 1; i <= rightShow; i++)
				{
					@:<label class="pagingNumber">@i</label>
				}
				@:......
				for (int i = totalPage - leftShow + 1; i <= totalPage; i++)
				{
					@:<label class="pagingNumber">@i</label>
				}
				@:<label class="pagingNumber">></label>
				@:<label class="pagingNumber">>></label>
			}
			else
			{
				if (totalPage - currentPage <= rightShow)
				{
					@:<label class="pagingNumber"><<</label>
					@:<label class="pagingNumber"><</label>
					@:......
					for (int i = totalPage - rightShow - leftShow + 1; i <= totalPage; i++)
					{
						@:<label class="pagingNumber">@i</label>
					}
					@:<label class="pagingNumber">></label>
					@:<label class="pagingNumber">>></label>
				}
				else
				{
					@:<label class="pagingNumber"><<</label>
					@:<label class="pagingNumber"><</label>
					@:......
					for (int i = currentPage - 2; i <= currentPage + 2; i++)
					{
						@:<label class="pagingNumber">@i</label>
					}
					@:......
					for (int i = totalPage - leftShow + 1; i <= totalPage; i++)
					{
						@:<label class="pagingNumber">@i</label>
					}
					@:<label class="pagingNumber">></label>
					@:<label class="pagingNumber">>></label>
				}
			}
		}
	}
	&nbsp;&nbsp;&nbsp;
	Show
	<select id="cbxPageSize">
		<option value="20">20</option>
		<option value="50">50</option>
		<option value="100">100</option>
		<option value="200">200</option>
	</select>
</div>

<script type="text/javascript">
	$(document).ready(function () {
		$('.pagingNumber').click(function (e) {
			var currentPage = @Model.PageIndex;
			var totalPage = @Model.TotalPages;
			var pageSize = $('#cbxPageSize').val();

			var $this = $(this);
			var value = $this.html();
			alert(value);
			if (value == "<<") {
				currentPage = 1;
			}
			else if (value == "<") {
				if (currentPage != 1) {
					currentPage--;
				}
			}
			else if (value == ">") {
				if (currentPage != totalPage) {
					currentPage++;
				}
			}
			else if (value == ">>") {
				currentPage = totalPage;
			}
			else {
				currentPage = parseInt(value);
			}

			alert(currentPage + ", " + totalPage + ", " + pageSize);
		});

		function getAction() {
			return $("#frmSearch").attr('action');
		};

		function collectData() {
			return $('#frmSearch').serialize();
		};
	});
</script>